<script setup lang="ts">
import { Subject,get_subjects } from './subject'

const router=useRouter()
const subjects=ref([] as Subject[])


// const emit=defineEmits(['goto'])

// const handle_select=(index:string,indexPath:string,item:string)=>{
//     console.log(index,indexPath,item)
//     emit('goto',index)
// }

const route_to_tiku=(type:string,token:number|null=null)=>{
    console.log('Router to tiku',type,token)
    router.push({
        name:'tiku',
        params:{
            type:type,
            token:token,
        }
    })
}



onMounted(async ()=>{
    subjects.value=await get_subjects()    
    router.push({
        name:'tiku',
        params:{type:'year'}
    })
    // router.push({
    //     name:'exam',
    //     params:{
    //         questions:[10,11,12,13],
    //         start:0,
    //     }
    // })
})
</script>

<template>
  <el-menu
    :default-openeds="['1','1-2']"
    background-color="#333333"
    text-color="#dddddd"
    active-text-color="#1e90ff">
      <el-sub-menu index="1">
          <template #title>
              <h1>题库</h1>
          </template>
            <el-menu-item index="1-1">
                <h2 @click="route_to_tiku('year')">按年份</h2>
            </el-menu-item>
            <el-sub-menu index="1-2">
                <template #title>
                <h1>按学科</h1>
                </template>
                <el-menu-item v-for="subject in subjects" :key="subject.id" :index="'1-2-'+subject.id">
                    <h2 @click="route_to_tiku('subject',subject.id)">{{subject.title}}</h2>
                </el-menu-item>
            </el-sub-menu>
            <el-menu-item index="1-3">
                    <h2>错题集</h2>
            </el-menu-item>
      </el-sub-menu>
      <el-menu-item index="2">
          <router-link to="/exam">
            <h1>刷题</h1>
          </router-link>
      </el-menu-item>
  </el-menu>
</template>

<style scoped>
a{
    text-decoration: none;
    color: aliceblue;
}
a:target{
    color: #1e90ff;
}
</style>
